﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using HotelManagement.DTO;
using HotelManagement.BLO;

namespace HotelManagement.Services
{
    public partial class ServiceEdit : Form
    {
        CheckInput ck;
        public ServiceEdit()
        {
            InitializeComponent();
            Init();
            txtServiceID.Text = "";
        }
        

        public ServiceEdit(ServiceDTO service)
        {
            InitializeComponent();
            Init();

            this.txtServiceID.Text = service.ServiceID.ToString();
            this.txtServiceName.Text = service.ServiceName;
            this.cmbServiceUnit.Text = service.Unit;
            txtServicePrice.Text = service.Price.ToString();
        }
        private void Init()
        {
            ck = new CheckInput();
            this.cmbServiceUnit.DataSource = CheckInput.lstServiceUnit;
        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            ServiceBLO bloS = new ServiceBLO();
            ServiceDTO serv = new ServiceDTO();

            serv.ServiceName = txtServiceName.Text;
            
            serv.Price = float.Parse(txtServicePrice.Text);

            if (txtServiceID.Text != "")
            {
                if (cmbServiceUnit.SelectedIndex == 0)
                {
                    MessageBox.Show("Chưa chọn đơn vị");
                    return;
                }
                serv.ServiceID = int.Parse(txtServiceID.Text);
                serv.Unit = cmbServiceUnit.Text;
                if (bloS.Update(serv))
                {
                    this.DialogResult = DialogResult.OK;
                }
                else
                    DialogResult = DialogResult.Cancel;
                return;
            }
            if (cmbServiceUnit.SelectedIndex==0)
            {
                serv.Unit = "";
            }
            if (bloS.Insert(serv))
            {
                this.DialogResult = DialogResult.OK;
            }
            else
                DialogResult = DialogResult.Cancel;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
        }
    }
}
